package com.lsa.letcode.the64.minPathSum;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import com.lsa.helpers.Utils;

public class MinPathSumTest {
	@Test
	public void test() throws IOException {
		Solution s = new Solution();
		test(s, new int[][]{
				{10,10,10}
		}, 30);
		test(s, new int[][]{
				{10},
				{10},
				{10}
		}, 30);
		test(s, new int[][]{
				{10,10,10},
				{11,10,9},
				{11,12,9}
		}, 48);
		
		test(s, new int[][]{
				{10,10,10},
				{1,10,9},
				{2,3,9}
		}, 25);
		
		test(s, new int[][]{
				{10,10,10,10},
				{10,10,10,10},
				{10,10,10,10},
		}, 60);
		
		test(s, new int[][]{
				{10},
		}, 10);
		
		test(s, new int[][]{
				{10,10,10,10},
				{10,10,10,10},
				{10,10,10,10},
				{10,10,10,10},
		}, 70);
		
		test(s, new int[][]{
				{10,1,1,2},
				{1,1,2,2},
				{1,1,1,2},
				{1,10,1,10},
		}, 25);

		for (int i = 0; i < 4; i++) {
			test(s, "array1.txt", 823);
		}
		
//		Map<Integer, Integer> m = new HashMap<Integer, Integer>();
//		
//		for (int i = 0; i < 200; i++) {
//			for (int j = 0; j < 200; j++) {
//			}
//		}
//		
//		System.out.println(new Solution.Cell(0, 100, 0).hashCode() + " " + new Solution.Cell(100, 0, 0).hashCode());
	}

	private void test(Solution s, String arrayName, int expected)
			throws IOException {
		InputStream in = this.getClass().getResourceAsStream(arrayName);
		int[][] arr = Utils.listTo2dArray(Utils.readList(in, '[', ']'));
		assertEquals(expected, s.minPathSum(arr));
	}

	private void test(Solution s, int[][] grid, int expected) {
		assertEquals(expected, s.minPathSum(grid));
	}
}
